package com.demo.project_template.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.demo.project_template.entity.UserGoldRecord;
import com.demo.project_template.service.UserGoldRecordService;
import com.demo.project_template.vo.response.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 金币变动记录表 前端控制器
 * </p>
 *
 * @author 杨玉龙
 * @since 2024-08-20 18:10:02
 */
@Api(tags = "用户金币变动记录")
@RestController
@RequestMapping("/userGoldRecord")
public class UserGoldRecordController {
    @Resource
    private UserGoldRecordService userGoldRecordService;

    @ApiOperation(value = "查询用户金币变动记录")
    @GetMapping(value = "/page")
    public R<IPage<UserGoldRecord>> page(@RequestParam Integer pageNo,
                                         @RequestParam Integer pageSize,
                                         @RequestParam Long userId,
                                         @RequestParam(required = false) String date){
        Page<UserGoldRecord> page = userGoldRecordService.page(new Page<>(pageNo, pageSize),
                new LambdaQueryWrapper<UserGoldRecord>()
                        .eq(UserGoldRecord::getUserId, userId)
                        .like(UserGoldRecord::getCreateTime, date));
        return R.success(page);
    }
}
